package spring.mvc.controller;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/pages")
public class LoginController {
	protected static Logger logger = Logger.getLogger("controller");

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String getLoginPage(
			@RequestParam(value = "ERROR", required = false) boolean error,
			ModelMap model) {
		logger.debug("Received request to show login page");
		if (error = true) {
			model.put("ERROR", "Invalid username or password!");
		} else {
			model.put("ERROR", "");
		}
		return "login";
	}

	@RequestMapping(value = "/denied", method = RequestMethod.GET)
	public String getDeniedPage() {
		logger.debug("Received request to show denied page");
		return "denied";
	}

	// @RequestMapping(value = "/logout", method = RequestMethod.GET)
	// public String logout(ModelMap model) {
	// return "login";
	// }
}
